#include <iostream>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>

#include <csignal>
#include <cstdio>
#include <QApplication>
#include <QDir>
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QDebug>

#include "MainWindowShow.h"//主界面
#include "RunConfig.h"//加载运行配置
#include "RtspDecodeThread.h"//解码线程


using namespace std;

//主函数
int main(int argc, char *argv[]){
    cout << "qt_rtsp_show_ui ~~~\n";
    
    QApplication app(argc, argv);
    app.setOverrideCursor(Qt::BlankCursor);//隐藏指针

    QCommandLineParser parser;
    parser.setApplicationDescription("RTSP Show UI");
    parser.addHelpOption();
    parser.addVersionOption();

    QCommandLineOption configFilePathOption("config", "The path to the configuration file.", "path");
    parser.addOption(configFilePathOption);

    parser.process(app);

    if (!parser.isSet(configFilePathOption)) {
        qWarning() << "Configuration file path is not set. Please provide a path using --config <path>";
        return -1;
    }

    QString configFilePath = parser.value(configFilePathOption);

    //读取配置
    RunConfig config(configFilePath.toStdString());

    //创建解码线程
    RtspDecodeThread dec_thread(config);
    
    // 创建并显示主窗口
    MainWindowShow mainWindow(dec_thread,config);
    if (config.getBool("dubug", false))
    {
        mainWindow.show();
    }else
    {
        mainWindow.showFullScreen();//全屏显示
    }


    //摄像头图像更新设置
    QObject::connect(&dec_thread, &RtspDecodeThread::frameDecoded, &mainWindow, &MainWindowShow::updateFrame);
    //报错信息弹窗显示
    QObject::connect(&dec_thread,&RtspDecodeThread::pop_warning,&mainWindow,&MainWindowShow::handl_warnings);

    dec_thread.startDecoding();//开启解码线程
    

    return app.exec();
}



